/* 
 * 活动设置管理界面.
 */

import { Component, OnInit } from '@angular/core';
import { RestService} from '../services/RestService';
import { Bingo } from '../domain/Bingo';
import { Prize } from '../domain/Prize';

@Component({
    selector: 'page-bingo',
    templateUrl: './bingo.component.html',
    styleUrls: ['./bingo.component.css']
})
export class BingoComponent implements OnInit{
	
	bingo : Bingo;
	
	prizes : Prize[];
	
    constructor(private restService: RestService) { 
		this.bingo = new Bingo();
		this.prizes = new Array();
	}
    
	
    ngOnInit() {
		console.log("开始查询...");

		this.init();

		// 下面打印时，都是空值，
		// 也就是说上面请求是异步的，但方法内部是同步的
		//console.log(this.bingo.title + ":" + this.prizes.length)
    }

    // 同步执行...
    async init() {
    	console.log("初始化奖项设置界面...");

    	// 这里是同步顺序执行的
		// 不需要写成then的两个嵌套
        this.bingo = await this.restService.getCurrentBingo();
        this.prizes = await this.restService.getPrizesByBingo(this.bingo.id);
	}

}

